package com.utils.rsa;

import org.apache.commons.codec.binary.Hex;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class SHA256Utils {
    private static final String ALGORITHM_SHA256 = "SHA-256";

    public static void main(String[] args) throws NoSuchAlgorithmException {
        byte[] bytes = "加密的文件前64位加密的文件前64位加密的文件前".getBytes(StandardCharsets.UTF_8);
        System.out.println(bytes.length);
        byte[] digest = getSHA256Bytes(bytes);
        char[] chars = Hex.encodeHex(digest);
        System.out.println(digest.length);
        System.out.println(chars.length);
        System.out.println(chars);
        System.out.println(Arrays.toString(digest));

    }

    public static byte[] getSHA256Bytes(byte[] bytes) throws NoSuchAlgorithmException {
        MessageDigest messageDigest = MessageDigest.getInstance(ALGORITHM_SHA256);
        messageDigest.update(bytes);
        return messageDigest.digest();
    }
}
